<template>
  <div class="container">
    <el-container>
      <el-header>
        <h1>银行账户管理系统</h1>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-col :span="24">
            <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">
              <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>交易记录</span>
                </template>
                <el-menu-item index="1-1">存款记录</el-menu-item>
                <el-menu-item index="1-2">取款记录</el-menu-item>
                <el-menu-item index="1-2">转账记录</el-menu-item>
              
              </el-submenu>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>账户管理</span>
                </template>
                <el-menu-item index="2-1">用户信息管理</el-menu-item>
                <el-menu-item index="2-2">账户信息管理</el-menu-item>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-aside>
        <el-container>
          <el-main>
            <!-- 新增、删除、修改按钮 -->
            <div style="float: right; margin-bottom: 20px;">
              <el-button type="primary" @click="handleAdd">新增</el-button>
              <el-button type="danger" @click="handleDelete">删除</el-button>
              <el-button @click="handleEdit">修改</el-button>
            </div>
            <el-table :data="tableData" border show-summary style="width: 100%;" class="custom-table">
              <el-table-column prop="id" label="ID" width="180">
              </el-table-column>
              <el-table-column prop="name" label="姓名">
              </el-table-column>
              <el-table-column prop="phone" sortable label="数值 1">
              </el-table-column>
              <!-- <el-table-column prop="amount2" sortable label="数值 2">
              </el-table-column>
              <el-table-column prop="amount3" sortable label="数值 3">
              </el-table-column> -->
            </el-table>
          </el-main>
          <el-footer>
            <div class="block">
              <span class="demonstration"></span>
              <el-pagination layout="prev, pager, next" :total="50">
              </el-pagination>
            </div>
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  mounted() {
    this.fetchData(); // 在组件挂载后立即调用 fetchData  
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += ' 元';
        } else {
          sums[index] = 'N/A';
        }
      });

      return sums;
    },
    //查询方法
    fetchData() {
      axios.get('http://localhost:8080/api/user') // 替换为你的API URL  
        .then(response => {
          console.log('获取到的数据:', response.data); // 打印获取到的数据  
          this.tableData = response.data;
        })
        .catch(error => {
          console.error("获取数据失败:", error);
        });
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // 新增的方法  
    handleAdd() {
      // 实现新增的逻辑，例如打开一个模态框让用户输入数据  
      console.log('新增按钮被点击');
    },
    // 删除的方法  
    handleDelete() {
      // 实现删除的逻辑，需要先选择一行或多行  
      console.log('删除按钮被点击');
    },
    // 修改的方法  
    handleEdit() {
      // 实现修改的逻辑，同样需要先选择一行  
      console.log('修改按钮被点击');
    },
  },
  data() {
    return {
      tableData: []
    };
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.el-header {
  background-color: #58b7e3;
  color: #ffffff;
  text-align: center;
  line-height: 20px;
  height: 100px !important;
}

.el-footer {
  background-color: #ffffff;
  color: #333;
  text-align: center;
  line-height: 20px;
}

.el-aside {
  background-clip: border-box;

  color: #333;
  text-align: center;
  line-height: 400px;
  height: 670px !important;
}

.el-main {
  background-color: #78d8e9;
  color: #ffffff;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.custom-table .el-table__header-wrapper th {
  /* 设置头部单元格的高度 */
  height: 60px;
  /* 调整为你希望的高度 */
  /* 可能还需要调整其他样式，如行内填充（padding）等 */
  padding: 0 20px;
  /* 示例：调整内填充 */
  line-height: 60px;
  /* 使文本垂直居中 */
}
</style>